import re
import subprocess as subextract
import shlex

url = raw_input("Enter an url: ")


if(url[:4] == 'http'):
    url = url[7:]
elif(url[:5] == 'https'):
    url = url[8:]

cmd = ["dig", url, "-t", "A"]
ip, err = sub.Popen(cmd, stdin = sub.PIPE, stdout = sub.PIPE, stderr = sub.PIPE).communicate()




# Testing checking the IP TTL value.












#check that the following two answers give the same IP address
#dig @8.8.8.8 url +short
#dig url +short


#cmd1 = ["dig", "@8.8.8.8", url, "+short"]
#cmd2 = ["dig", url, "+short"]
#out1, err1 = sub.Popen(cmd1, stdin = sub.PIPE, stdout = sub.PIPE, stderr = sub.PIPE).communicate()
#out2, err2 = sub.Popen(cmd2, stdin = sub.PIPE, stdout = sub.PIPE, stderr = sub.PIPE).communicate()
#print(out1 == out2)

#if(url[:5] == 'http:'):
#    val = Popen('host -a ' + url[7:], shell=True, stdin = PIPE, stdout = PIPE, stderr = STDOUT)
#    print(val.communicate()[0])
#elif(url[:5] == 'https'):
#    val = Popen('host -a ' + url[8:], shell=True, stdin = PIPE, stdout = PIPE, stderr = STDOUT)
#    print(val.communicate()[0])
#else:
#    val = Popen('host -a ' + url, shell=True, stdin = PIPE, stdout = PIPE, stderr = STDOUT)
#    print(val.communicate()[0])


#cmd='dig @ns1.netnames.net www.rac.co.uk +short'
# cmd='dig @ns1.netnames.net www.rac.co.uk CNAME'
#proc=subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE)
#out,err=proc.communicate()
#print(out)

# rac-secure.gslb.norwichunion.com.









#  IP Regex.
#ip = re.search(r'((2[0-5]|1[0-9]|[0-9])?[0-9]\.){3}((2[0-5]|1[0-9]|[0-9])?[0-9])', s)
#port = re.search(r':[0-9]+', s)
#if ip is not None:
#    print("Found IP Address:")
#    print(ip.group())
#if port is not None:
#    print("Found port number:")
#    print(port.group())


